package com.gzx.plugin.tjzy.modular.sms.batch.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzx.plugin.tjzy.modular.sms.batch.bo.GzxSmsBatchAddBo;
import com.gzx.plugin.tjzy.modular.sms.batch.bo.GzxSmsBatchQueryBo;
import com.gzx.plugin.tjzy.modular.sms.batch.service.GzxSmsService;
import com.gzx.plugin.tjzy.modular.sms.batch.vo.GzxSmsBatchVo;
import com.gzx.plugin.tjzy.modular.sms.batch.vo.GzxSmsDetailVo;
import com.gzx.plugin.tjzy.modular.sms.batch.vo.GzxStatisticVo;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.annotation.CommonNoRepeat;
import vip.xiaonuo.common.pojo.CommonResult;

/**
 * @author zjt
 * @description
 * @date 2025/3/6 18:45
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/tjzy/sms")
public class GzxSmsBatchController {

    private final GzxSmsService smsService;

    @PostMapping("/pageList")
    public CommonResult<Page<GzxSmsBatchVo>> pageList(@RequestBody GzxSmsBatchQueryBo smsBatchQueryBo) {
        return CommonResult.data(smsService.pageList(smsBatchQueryBo));
    }

    @PostMapping("/pageDetail")
    public CommonResult<Page<GzxSmsDetailVo>> pageDetail(@RequestBody GzxSmsBatchQueryBo smsBatchQueryBo) {
        return CommonResult.data(smsService.pageDetail(smsBatchQueryBo));
    }

    @CommonLog("短信发送导入")
    @PostMapping("/importExcel")
    public CommonResult<String> importExcel(@RequestPart("smsBatchAddBo") GzxSmsBatchAddBo smsBatchAddBo, @RequestPart("multipartFile") MultipartFile multipartFile) {
        return CommonResult.data(smsService.importExcel(smsBatchAddBo, multipartFile));
    }

    @CommonNoRepeat
    @CommonLog("短信发送测试")
    @GetMapping("/testSend/{batchNumber}")
    public CommonResult<Void> testSend(@PathVariable String batchNumber) {
        smsService.testSend(batchNumber);
        return CommonResult.ok();
    }

    @CommonLog("短信发送开始")
    @GetMapping("/startSend/{batchNumber}")
    public CommonResult<Void> startSend(@PathVariable String batchNumber) {
        smsService.startSend(batchNumber);
        return CommonResult.ok();
    }

    @PostMapping("/export")
    public void export(@RequestBody GzxSmsBatchQueryBo smsBatchQueryBo, HttpServletResponse httpServletResponse) {
        smsService.export(smsBatchQueryBo, httpServletResponse);
    }

    /**
     * 短信发送统计
     */
    @CommonLog("短信发送统计")
    @GetMapping("/smsStatistic/{batchNumber}")
    public CommonResult<GzxStatisticVo> smsStatistic(@PathVariable String batchNumber) {
        return CommonResult.data(smsService.smsStatistic(batchNumber));
    }
}
